<script setup>
import { inject, ref } from "vue";
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
import { lowerList } from "@/services/team";
import { areaListApi } from "@/services/address";
import { userareaLower, lowerCount, rolledcount } from "@/services/team";
import { mine, userinfo } from "@/services/user";
import { des_phone } from "@/utils/desensitization";
userinfofun();

async function userinfofun() {
  let res = await userinfo();
  dltext.value = res.data.area_code_text;
}

onLoad((e) => {
  formdata.value.level = e;

  getuserlist();
});
//下拉触底
onReachBottom(() => {
  getuserlist();
});
const formdata = ref({
  page: 1,
  limit: 10,
  keyword: "",
  level: "",
});
const list = ref([]);
const shownodate = ref(false);

const loading = ref(true);
const status = ref("more");

async function getuserlist() {
  loading.value = true;
  try {
    let res = await userareaLower(formdata.value);
    if (res.code == 200) {
      // list.value = res.data.list;
      list.value = list.value.concat(res.data.list);
      shownodate.value = true;
      if (res.data.list.length < formdata.value.limit) {
        status.value = "no-more";
      } else {
        status.value = "more";
      }
      loading.value = false;
      if (res.data.list.length > 0) {
        formdata.value.page = formdata.value.page + 1;
      }
    }
  } catch (e) {
    uni.$u.toast(e.info);
  }
}

const searchfun = () => {
  list.value = [];
  formdata.value.page = 1;
  getuserlist();
};

// 地区
const dltext = ref("");

const callphone = (item) => {
  uni.makePhoneCall({
    phoneNumber: item.ot_phone,
  });
};
</script>

<template>
  <view class="areateam">
    <view class="content-top">
      <view class="content-top-search">
        <up-search
          placeholder="搜索姓名/手机号"
          :showAction="false"
          v-model="formdata.keyword"
          @search="searchfun"
        ></up-search>
      </view>
    </view>

    <view class="footer" v-if="list.length > 0">
      <view class="footer-content" v-for="(item, index) in list" :key="index">
        <view class="footer-content-left">
          <view class="footer-content-name">{{
            item.name ? item.name : item.nickname ? item.nickname : "---"
          }}</view>
          <view
            class="footer-content-identity"
            :class="item.level_id ? 'lv-name-' + item.level_id : 'lv-name-qy'"
            >{{ item.level && item.level.name ? item.level.name : "" }}</view
          >
        </view>

        <view class="footer-content-right" @click="callphone(item.phone)">
          <view class="footer-content-phone">{{
            des_phone(item.phone ? item.phone : "---")
          }}</view>
          <view class="footer-content-img">
            <image
              src="@/static/team/shopkeeper/phone-icon.png"
              mode="widthFix"
            />
          </view>
        </view>

        <view class="footer-content-item"
          >代理区域：{{ item.area_code_text }}</view
        >
      </view>
    </view>
    <uni-load-more color="#c6c5c3" :status="status" v-if="list.length > 0" />
  </view>
</template>

<style lang="scss" scoped>
@import "./areaTeam.scss";
</style>
